package com.example.web.service.cabinetstatus.impl;

import com.example.web.service.TimeIteratorNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.regex.Pattern;

@Slf4j
@Order(3)
@Component
public class OrdinaryIteratorNodeImpl extends TimeIteratorNode {
    @Override
    public boolean condition(String timeStr) {
        log.info("check Ordinary");
        String pattern = "^\\d{1,4}(-)(1[0-2]|0?[1-9])\\1(0?[1-9]|[1-2]\\d|30|31)$";
        return Pattern.matches(pattern, timeStr);
    }

    @Override
    public LocalDateTime parse(String timeStr) {
        log.info("use Ordinary");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(timeStr, formatter);
    }
}
